package yxy.game.pm2.bean.db.newDao;

import yxy.apple.db.DbManager;
import yxy.game.pm2.bean.db.po.AvatarPo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author James
 * @date 2022/1/22 15:12
 **/
public class AvatarDAO {
    private static final String
            REPLACE_ONE = "replace into `avatar` (`pCode`, `dataCode`, `newFound`, `conditions`) values (?,?,?,?)",
            SELECT_ALL = "select * from `avatar` where `pCode` = ?";

    public static List<AvatarPo> getList(String playerCode) {
        return DbManager.instance().executeQueryObjectList(SELECT_ALL, new Object[]{playerCode}, AvatarPo.builder);
    }

    public static boolean replace(List<AvatarPo> avatarPos) {
        List<Object[]> list = new ArrayList<>();
        for (AvatarPo avatarPo : avatarPos) {
            Object[] objects = new Object[]{avatarPo.getPlayerCode(),avatarPo.getDataCode(),avatarPo.isNewFound(),avatarPo.getConditions()};
            list.add(objects);
        }
        int[] ints = DbManager.instance().executeBatchCommand(REPLACE_ONE, list);
        return ints.length == avatarPos.size();
    }

}
